home *** CD-ROM | disk | FTP | other *** search
/ InfoMagic Internet Tools 1993 July / Internet Tools.iso / RockRidge / mail / pine / imap-3.0 / non-ANSI / c-client / nntp.c < prev    next >
Encoding:
C/C++ Source or Header  |  1993-06-10  |  3.3 KB  |  98 lines

  1. /*
  2.  * Program:    Network News Transfer Protocol (NNTP) routines
  3.  *
  4.  * Author:    Mark Crispin
  5.  *        Networks and Distributed Computing
  6.  *        Computing & Communications
  7.  *        University of Washington
  8.  *        Administration Building, AG-44
  9.  *        Seattle, WA  98195
  10.  *        Internet: MRC@CAC.Washington.EDU
  11.  *
  12.  * Date:    10 February 1992
  13.  * Last Edited:    10 June 1993
  14.  *
  15.  * Copyright 1993 by the University of Washington.
  16.  *
  17.  *  Permission to use, copy, modify, and distribute this software and its
  18.  * documentation for any purpose and without fee is hereby granted, provided
  19.  * that the above copyright notices appear in all copies and that both the
  20.  * above copyright notices and this permission notice appear in supporting
  21.  * documentation, and that the name of the University of Washington not be
  22.  * used in advertising or publicity pertaining to distribution of the software
  23.  * without specific, written prior permission.  This software is made
  24.  * available "as is", and
  25.  * THE UNIVERSITY OF WASHINGTON DISCLAIMS ALL WARRANTIES, EXPRESS OR IMPLIED,
  26.  * WITH REGARD TO THIS SOFTWARE, INCLUDING WITHOUT LIMITATION ALL IMPLIED
  27.  * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE, AND IN
  28.  * NO EVENT SHALL THE UNIVERSITY OF WASHINGTON BE LIABLE FOR ANY SPECIAL,
  29.  * INDIRECT OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING
  30.  * FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, TORT
  31.  * (INCLUDING NEGLIGENCE) OR STRICT LIABILITY, ARISING OUT OF OR IN
  32.  * CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
  33.  *
  34.  */
  35.  
  36.  
  37. #include <ctype.h>
  38. #include <stdio.h>
  39. #include "mail.h"
  40. #include "osdep.h"
  41. #include "smtp.h"
  42. #include "nntp.h"
  43. #include "rfc822.h"
  44. #include "misc.h"
  45.  
  46. /* Network News Transfer Protocol open connection
  47.  * Accepts: service host list
  48.  *        initial debugging flag
  49.  * Returns: T on success, NIL on failure
  50.  */
  51.  
  52. SMTPSTREAM *nntp_open (hostlist,debug)
  53.     char **hostlist;
  54.     long debug;
  55. {
  56.   SMTPSTREAM *stream = NIL;
  57.   void *tcpstream;
  58.   if (!(hostlist && *hostlist)) mm_log ("Missing NNTP service host",ERROR);
  59.   else do {            /* try to open connection */
  60.     if (tcpstream = tcp_open (*hostlist,NNTPTCPPORT)) {
  61.       stream = (SMTPSTREAM *) fs_get (sizeof (SMTPSTREAM));
  62.       stream->tcpstream = tcpstream;
  63.       stream->debug = debug;
  64.       stream->reply = NIL;
  65.                 /* get NNTP greeting */
  66.       if (smtp_reply (stream) == NNTPGREET) return stream;
  67.       smtp_close (stream);    /* otherwise punt stream */
  68.     }
  69.   } while (*++hostlist);    /* try next server */
  70.   return NIL;
  71. }
  72.  
  73. /* Network News Transfer Protocol deliver news
  74.  * Accepts: stream
  75.  *        message envelope
  76.  *        message body
  77.  * Returns: T on success, NIL on failure
  78.  */
  79.  
  80. long nntp_mail (stream,env,body)
  81.     SMTPSTREAM *stream;
  82.     ENVELOPE *env;
  83.     BODY *body;
  84. {
  85.   char tmp[8*MAILTMPLEN];
  86.                 /* negotiate post command */
  87.   if (!(smtp_send (stream,"POST",NIL) == NNTPREADY)) return NIL;
  88.                 /* set up error in case failure */
  89.   smtp_fake (stream,SMTPSOFTFATAL,"NNTP connection went away!");
  90.                 /* RFC-1036 requires this cretinism */
  91.   sprintf (tmp,"Path: %s!%s\015\012",tcp_localhost (stream->tcpstream),
  92.        env->from ? env->from->mailbox : "foo");
  93.                 /* output data, return success status */
  94.   return tcp_soutr (stream->tcpstream,tmp) &&
  95.     rfc822_output (tmp,env,body,smtp_soutr,stream->tcpstream) &&
  96.       (smtp_send (stream,".",NIL) == NNTPOK);
  97. }
  98.